#include <bits/stdc++.h>
using namespace std;

class Solution
{
public:
    vector<int> findAnagrams(string s, string p)
    {
        vector<int> ans;
        vector<int> p_v(26, 0);
        vector<int> s_v(26, 9);
        for (int i = 0; i < p.size(); ++i)
        {
            p_v[p[i] - 'a']++;
            s_v[s[i] - 'a']++;
        }
        for (int i = 0; i < s.size() - p.size(); ++i)
        {
            if (p_v == s_v)
            {
                ans.push_back(i);
            }
            p_v[s[i] - 'a']--;
            p_v[s[i + p.size()]]++;
        }
        return ans;
    }
};